*******************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Table C2: Figure 8 in table form
*******************************

//Setup
	do "$dofiles/00_setup.do"

//Load master data
	use irca_gerrymander.dta, clear
		
	//Controls
	global controls  c.pop1990#i.p102 c.inc_pc1990#i.p102  c.age_share1990#i.p102 c.unemployment_1990#i.p102 c.educ1990##i.p102 c.births_1990#i.p102 c.black_share1990#i.p102 c.white_share1990#i.p102
	
	global controls_full  c.pop1990##i.p102##i.legal_control_kaplan1991 c.inc_pc1990##i.p102##i.legal_control_kaplan1991  c.age_share1990##i.p102##i.legal_control_kaplan1991 c.unemployment_1990##i.p102##i.legal_control_kaplan1991 c.educ1990##i.p102##i.legal_control_kaplan1991 c.births_1990##i.p102##i.legal_control_kaplan1991 c.black_share1990##i.p102##i.legal_control_kaplan1991 c.white_share1990##i.p102##i.legal_control_kaplan1991
	
	//VRA controls
	global vra_control i.vra_covered##i.p102
	global vra_full i.vra_covered##i.p102##i.legal_control_kaplan1991 
	
	//Extra controls
	global extras c.povrate_1990#i.p102 c.hsd_share1990#i.p102 c.spr010_1990#i.p102 c.spr030_1990#i.p102 c.housing_value_1990#i.p102 c.crime_1990#1.p102
	
	 //1980 Controls
	global controls1980 c.population_bea1980#i.p102 c.income_pc1980#i.p102  c.age_share1980#i.p102 c.edu6351980#i.p102 c.births_1980#i.p102 c.black_share1980#i.p102 c.white_share1980#i.p102
	
	//Controls pre post 1980 redistricting.
	global controls97 c.pop1990#i.p97 c.inc_pc1990#i.p97  c.age_share1990#i.p97 c.unemployment_1990#i.p97 c.educ1990##i.p97 c.births_1990#i.p97 c.black_share1990#i.p97 c.white_share1990#i.p97
	
	//Vra controls: pre post 1980 redistricting
	global vra_control97 i.vra_covered##i.p97 
	
	//Fixed effects
	global fe id congress#StateFIPS c.hisp_share1980#i.congress i.unassigned_county#i.year 
	
	//Clustering
	global cluster id

	
****************
* Robustness Results
****************
//Polsby Popper
eststo clear
	 //Baseline
	reghdfe hisp_majority_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //No controls
	reghdfe hisp_majority_county c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Extra controls
	reghdfe hisp_majority_county $controls $vra_control $extras c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//1980 Controls
	reghdfe hisp_majority_county $controls1980 $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)	
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 	
	
	//Interacted Observables (Fully Saturated)
	reghdfe hisp_majority_county $controls_full $vra_full c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	 //Alternative legal control
	reghdfe hisp_majority_county $controls $vra_control c.irca_std##i.p102##ib2.arp_nocommission [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Using Hispanic share instead of imputing
	reghdfe hisp_majority_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop imputed counties
	reghdfe hisp_majority_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Single-district counties
	reghdfe hisp_majority_county $controls $vra_control c.irca_std##i.p102##ib2.legal_control_kaplan1991 [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Drop New Mexico
	reghdfe hisp_majority_county $controls $vra_control c.irca_std##1.p102##ib2.legal_control_kaplan1991 [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p102==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
	
	//Falsification
	reghdfe hisp_majority_county  $controls97 $vra_control97 c.irca_std##i.p97##ib2.legal_control_kaplan1981 , a($fe) cluster($cluster)
	sum hisp_majority_county if e(sample) & p97==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	eststo 
			
	***********************
	*	Generate Table
	**********************		

estfe 	est*
esttab  est*	using "${output}/tabC2.tex", replace booktabs ///
				nonote noobs nogaps compress noeqlines se substitute(_ _) label interaction(" $\times " ) ///
				mgroups("Empirical Specifications" "Sample Restrictions" "Placebo", pattern(1 0 0 0 0 0 0 1 0 0 1) ///
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
				mtitles("\makecell{Baseline \\ Model}" "\makecell{No \\ Covariates}" "\makecell{Extra \\ Covariates}" "\makecell{1980 \\ Covariates}" "\makecell{Interacted \\ Observables}" "\makecell{Alternative \\ Legal Control}" "\makecell{Hispanic \\ Impute}" "\makecell{Drop \\ Imputed}" "\makecell{Single-District \\ Counties}" "\makecell{Drop New \\ Mexico}" "\makecell{1980 \\ Placebo}") ///
				scalars("N $N$" "clusters Clusters" "ymean $\bar{Y}_{102}$" "ysd [S.D.]") sfmt(%9.3gc) ///
				star(* 0.1 ** 0.05 *** 0.01) ///
				rename(1.p102#c.irca_pc1990_hisp_std 1.p102#c.irca_std ///
				1.p102#0.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102#0.legal_control_kaplan1991#c.irca_std ///
				1.p102#1.legal_control_kaplan1991#c.irca_pc1990_hisp_std 1.p102#1.legal_control_kaplan1991#c.irca_std ///
				1.p97#c.irca_std 1.p102#c.irca_std ///
				1.p97#0.legal_control_kaplan1981#c.irca_std 1.p102#0.legal_control_kaplan1991#c.irca_std ///
				1.p97#1.legal_control_kaplan1981#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std ///
				1.p102#1.arp_nocommission#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std) ///
			keep(1.p102#c.irca_std 1.p102#1.legal_control_kaplan1991#c.irca_std)
			
			
			
		//	IRCA$_{90}$ $\times$ Post $\times$ D 
		// \multicolumn{1}{|c}{	
		// \cmidrule(lr){2-8} \cmidrule(lr){9-12}
		// \multicolumn{7}{c}{
		
